interactiveTDialog <- function(){
	if( !require(tcltk) ) stop('This function depends on the tcltk package')
	if(!exists('slider.env')) slider.env<<-new.env()
	n <- 1; assign('n',tclVar(n),env=slider.env) #Degrees of freedom
	xmin <- -4; assign('xmin',tclVar(xmin),env=slider.env) 
	xmax <- 4; assign('xmax',tclVar(xmax),env=slider.env)
	ymin <- 0; assign('ymin',tclVar(ymin),env=slider.env)
	ymax <- 0.4; assign('ymax',tclVar(ymax),env=slider.env)
	sn <- 0  ; assign('sn',tclVar(sn), env=slider.env) #Show normal variable
	t.refresh <- function(...){
		n <- as.numeric(evalq(tclvalue(n), env=slider.env))
		xmin <- as.numeric(evalq(tclvalue(xmin), env=slider.env))
		xmax <- as.numeric(evalq(tclvalue(xmax), env=slider.env))
		ymin <- as.numeric(evalq(tclvalue(ymin), env=slider.env))
		ymax <- as.numeric(evalq(tclvalue(ymax), env=slider.env))
		xx <- seq(xmin,xmax, length=500)
		yy <- dt(xx,n)
		plot(xx,yy,type='l', xlim=c(xmin,xmax), ylim=c(ymin,ymax), ylab='Density',xlab='x')
		abline(h=0,col="gray")
		# Show standard normal plot
		sn <- as.numeric(evalq(tclvalue(sn), env=slider.env))
		if(sn) lines(xx, dnorm(xx,0,1), col='green')
	}
	
	m <- tktoplevel()
	tkwm.title(m,gettext("Interactive t Distribution", domain="R-RcmdrPlugin.TeachingExtras"))
	tkwm.geometry(m,'+0+0')
	
	# n
	tkpack(fr <- tkframe(m),side='top')
	tkpack(tklabel(fr, text=gettext("Degrees of freedom", domain="R-RcmdrPlugin.TeachingExtras"), width='20'),side='right')
	tkpack(sc <- tkscale(fr, command=t.refresh, from=1, to=30, orient='horiz', resolution=1, showvalue=T),	side='left')
	assign('sc',sc,env=slider.env)
	evalq(tkconfigure(sc, variable=n),env=slider.env)
	
	# show normal
	tkpack(fr <- tkframe(m), side='top')
	tkpack(sc <- tkcheckbutton(fr, command=t.refresh), side='left')
	tkpack(tklabel(fr, text=gettext("Show Standard Normal", domain="R-RcmdrPlugin.TeachingExtras"),width='25'), side='left')
	assign('sc', sc, env=slider.env)
	evalq(tkconfigure(sc, variable=sn), env=slider.env)
	
	# xmin
	tkpack(fr <- tkframe(m),side='top')
	tkpack(tklabel(fr, text="Xmin", width=6), side='left')
	tkpack(e <- tkentry(fr,width=8), side='left')
	assign('e',e,env=slider.env)
	evalq(tkconfigure(e, textvariable=xmin), env=slider.env)
	
	# xmax
	tkpack(tklabel(fr, text="Xmax", width=6), side='left')
	tkpack(e <- tkentry(fr,width=8), side='left')
	assign('e',e,env=slider.env)
	evalq(tkconfigure(e, textvariable=xmax), env=slider.env)
	
	# ymin
	tkpack(fr <- tkframe(m),side='top')
	tkpack(tklabel(fr, text="Ymin", width=6), side='left')
	tkpack(e <- tkentry(fr,width=8), side='left')
	assign('e',e,env=slider.env)
	evalq(tkconfigure(e, textvariable=ymin), env=slider.env)
	
	# ymax
	tkpack(tklabel(fr, text="Ymax", width=6), side='left')
	tkpack(e <- tkentry(fr,width=8), side='left')
	assign('e',e,env=slider.env)
	evalq(tkconfigure(e, textvariable=ymax), env=slider.env)
	
	tkpack(tkbutton(m, text=gettext("Refresh", domain="R-RcmdrPlugin.TeachingExtras"), command=t.refresh), side='left')
	tkpack(tkbutton(m, text=gettext("Exit", domain="R-RcmdrPlugin.TeachingExtras"), command=function()tkdestroy(m)), side='right')
	
}